<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title></title>
    <link rel="stylesheet" href="../assets/css/layui.css">
    <link rel="stylesheet" href="../assets/css/view.css"/>
    <link rel="stylesheet" href="../assets/css/style.css"/>
</head>
<body class="layui-tank">
<div class="layui-card">
    <form class="layui-form" action="/editUser" id="editUserForm" method="post">
        <div class="layui-form-item">
            <label class="layui-form-label">用户名:</label>
            <div class="layui-input-block">
                <input type="text" name="username"  readonly="readonly"  th:value="${user.username}" id="username" lay-verify="username" autocomplete="off" placeholder="请输入用户名" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">姓名:</label>
            <div class="layui-input-block">
                <input type="hidden" id="id" name="id" th:value="${user.id}">
                <input type="text" name="name"  id="name" lay-verify="name" th:value="${user.name}" autocomplete="off" placeholder="姓名" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">密码:</label>
            <div class="layui-input-block">
                <input type="password" name="password" lay-verify="password" value="123456" autocomplete="off" placeholder="请输入密码" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">角色:</label>
           <!-- <input  id="roleIds" name="roleIds" type="hidden" th:value="${roleIds}">-->
            <div th:each="role:${sysRolses}" style="display: inline;"  class="layui-field-box">
               <!-- <label>[[${role.name}]]</label>-->	<input type="checkbox" name="roleId" th:text="${role.name}"    th:checked="${#strings.contains(hasRoles, role.id)}"  th:value="${role.id}" id="roleId"  autocomplete="off" placeholder=""   class="layui-field-box layui-btn-xs">
            </div>
        </div>
    </form>
</div>
<div class=" tkbtnfxd">
    <button type="button" id="btn_confirm" lay-submit lay-filter="userForm"  class="layui-btn  layui-btn-normal float-right">确定</button>
    <button type="button" id="btn_cancel" class="layui-btn layui-btn-primary float-right">取消</button>
</div>
<script src="../assets/jquery.min.js"></script>
<script src="../assets/layui.all.js"></script>
<script>
    var element = layui.element;
    layui.use(['laypage', 'layer'], function(){
        var laypage = layui.laypage
            ,layer = layui.layer;
    });
    layui.use(['form'], function () {
        var form = layui.form;
        //监听提交
        form.on('submit(userForm)',function (data) {
            var chk_value =[];//定义一个数组
            $('input[name="roleId"]:checked').each(function(){//遍历每一个名字为interest的复选框，其中选中的执行函数
                chk_value.push($(this).val());//将选中的值添加到数组chk_value中
            });
            if(0==chk_value.length){
                layer.msg('请选择角色', {icon: 2});
            }else{
                $("#editUserForm").submit();
                var index =parent.layer.getFrameIndex(window.name)
                parent.layer.close(index)
            }
        });
    });
    //取消
    $('#btn_cancel').on('click', function(){
        layui.use('layer', function(){
            var layer = layui.layer;
            var index =parent.layer.getFrameIndex(window.name)
            parent.layer.close(index)
        });
    })

</script >
</body>
</html>
